package com.example.controller;

import com.example.common.Result;
import com.example.entity.Phone;
import com.example.service.PhoneService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 手机设备Controller
 */
@RestController
@RequestMapping("/api/phone")
public class PhoneController {
    
    @Resource
    private PhoneService phoneService;
    
    /**
     * 分页查询手机设备
     */
    @GetMapping("/page")
    public Result<PageInfo<Phone>> page(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String model) {
        PageInfo<Phone> pageInfo = phoneService.page(pageNum, pageSize, name, model);
        return Result.success(pageInfo);
    }
    
    /**
     * 根据ID查询手机设备
     */
    @GetMapping("/{id}")
    public Result<Phone> getById(@PathVariable Integer id) {
        Phone phone = phoneService.getById(id);
        return Result.success(phone);
    }
    
    /**
     * 新增手机设备
     */
    @PostMapping
    public Result<?> add(@RequestBody Phone phone) {
        phoneService.add(phone);
        return Result.success();
    }
    
    /**
     * 更新手机设备
     */
    @PutMapping
    public Result<?> update(@RequestBody Phone phone) {
        phoneService.update(phone);
        return Result.success();
    }
    
    /**
     * 删除手机设备
     */
    @DeleteMapping("/{id}")
    public Result<?> delete(@PathVariable Integer id) {
        phoneService.delete(id);
        return Result.success();
    }
} 